1 TREATMENT

1.1 Import the data:

datos <- read_excel("Base_Pembro_1L_febrero_24__v2.xlsx", sheet = "datos")
## New names:
## • `Estudios` -> `Estudios...14`
## • `Est_civil` -> `Est_civil...15`
## • `Comp_hogar` -> `Comp_hogar...16`
## • `MOSs` -> `MOSs...17`
## • `Ansiedad` -> `Ansiedad...18`
## • `Depresion` -> `Depresion...19`
## • `MNA` -> `MNA...20`
## • `MNA` -> `MNA...27`
## • `Estudios` -> `Estudios...29`
## • `Est_civil` -> `Est_civil...31`
## • `Comp_hogar` -> `Comp_hogar...32`
## • `MOSs` -> `MOSs...33`
## • `Ansiedad` -> `Ansiedad...36`
## • `Depresion` -> `Depresion...37`

We delete individuals 17 and 21 because of their missing values:

datos <- datos[-c(17, 21), ]

1.2 We combine repeated columns:

datos <- datos %>%
  mutate(estudios = coalesce(`Estudios...14`, `Estudios...29`)) %>%
  select(-`Estudios...14`, -`Estudios...29`)

datos <- datos %>%
  mutate(est_civil = coalesce(`Est_civil...15`, `Est_civil...31`)) %>%
  select(-`Est_civil...15`, -`Est_civil...31`)

datos <- datos %>%
  mutate(hogar = coalesce(`Comp_hogar...16`, `Comp_hogar...32`)) %>%
  select(-`Comp_hogar...16`, -`Comp_hogar...32`)

datos <- datos %>%
  mutate(MOOSs = coalesce(`MOSs...17`, `MOSs...33`)) %>%
  select(-`MOSs...17`, -`MOSs...33`)

datos <- datos %>%
  mutate(ansiedad = coalesce(`Ansiedad...18`, `Ansiedad...36`)) %>%
  select(-`Ansiedad...18`, -`Ansiedad...36`)

datos <- datos %>%
  mutate(depresion = coalesce(`Depresion...19`, `Depresion...37`)) %>%
  select(-`Depresion...19`, -`Depresion...37`)

datos <- datos %>%
  mutate(MNA = coalesce(`MNA...20`, `MNA...27`)) %>%
  select(-`MNA...20`, -`MNA...27`)

1.3 We eliminate variables that are not useful:

Elderly variables:

datos <- datos %>% select(-G8, -Audicion, -Barthel, -Lawton_Brody, -SPPB, -Caida_6m, -Pfeiffer, -Mini_mental, -Social_Gijon, -Yesavage,-CIRS, -Charlson,-Polifarmacia,
                          -Sd_geriatr, -Clasif_geriatr_SIOG1, -Clasif_geriatr_Balducci, -Observaciones, -`CD4+_C_CD45`, -`CD45+_C`, -CD3_C_Leuc, -LDH_PE, -Prot_PE,
                          -Alb_PE, -Hb_PE, -Leucoc_PE, -Neutr_PE,-Linf_PE, -Plaq_PE, -NLR_PE, -`NLRPE_corte 4`, -`NLRPE_corte 5`, - PLR_PE, -PNI_PE, -SII_PE)

Dates:

datos <- datos %>% select(-Fecha_SLP,-Fecha_últ_control,-Fecha_exitus,-Fecha_SG,-Fecha_nac, -Fecha_dx,-Fecha_inicio_pem)

Concret variables:

datos <- datos %>% select(-Estado_mut,-Tipo_mut_Tej,-Biopsia_liq,-Tipo_mut_Liq)

1.4 Changing of some names:

names(datos)[names(datos) == "Joven(0)_Anciano(1)"] <- "Anciano"
names(datos)[names(datos) == "%_perd_peso"] <- "Porcentaje_perdpeso"
names(datos)[names(datos) == "PD-L1"] <- "PD_L1"
names(datos)[names(datos) == "1ª_eval"] <- "primera_eval"
names(datos)[names(datos) == "1ªeval_num"] <- "primera_eval_num"
names(datos)[names(datos) == "Toxicidad_si/no"] <- "Toxicidad"
names(datos)[names(datos) == "Progresión_sí/no"] <- "Progresion"
names(datos)[names(datos) == "2ªL_sí/no"] <- "segunda_eval"
names(datos)[names(datos) == "Exitus_sí/no"] <- "Exitus"
names(datos)[names(datos) == "T"] <- "Tamaño_tumor"
names(datos)[names(datos) == "N"] <- "Afectacion_ganglionar"
names(datos)[names(datos) == "M"] <- "Afectacion_metastasica"

2 STUDY OF MISSING VALUES:

tabla_faltantes = datos %>%
  summarise(across(everything(), ~mean(is.na(.)))) %>%
  pivot_longer(everything(), names_to = "Columna", values_to = "Porcentaje_NA") %>%
  mutate(Porcentaje_NA = Porcentaje_NA * 100)
as.data.frame(tabla_faltantes[order(tabla_faltantes$Porcentaje_NA, decreasing = TRUE),])
##                     Columna Porcentaje_NA
## 1     CD127-/lowFoxP3+_%CD4     91.176471
## 2         CD25+FoxP3+_%Linf     91.176471
## 3          CD39+FoxP3+_%CD4     91.176471
## 4                CD4+_%CD45     91.176471
## 5                     CD45+     91.176471
## 6             CD45RA+_%Linf     91.176471
## 7        CD45RA+FoxP3+_%CD4     91.176471
## 8        Helios+FoxP3+_%CD4     91.176471
## 9    CD127-/lowFoxP3+_C_CD4     91.176471
## 10       CD25+FoxP3+_C_Linf     91.176471
## 11        CD39+FoxP3+_C_CD4     91.176471
## 12           CD45RA+_C_Linf     91.176471
## 13      CD45RA+FoxP3+_C_CD4     91.176471
## 14      Helios+FoxP3+_C_CD4     91.176471
## 15      CD25+CD127low_%Linf     73.529412
## 16     CD25+CD127low_C_Linf     73.529412
## 17          HLADR+Lin_%Leuc     64.705882
## 18                mDC_%Leuc     64.705882
## 19                pDC_%Leuc     64.705882
## 20    CD4_Central_Mem_%Linf     64.705882
## 21   CD4_Effector_Mem_%Linf     64.705882
## 22          CD4_Naïve_%Linf     64.705882
## 23          CD4_TEMRA_%Linf     64.705882
## 24    CD8_Central_Mem_%Linf     64.705882
## 25   CD8_Effector_Mem_%Linf     64.705882
## 26          CD8_Naïve_%Linf     64.705882
## 27          CD8_TEMRA_%Linf     64.705882
## 28            mDC_CD16_%mDC     64.705882
## 29            mDC_CD1c_%mDC     64.705882
## 30          mDC_Clec9A_%mDC     64.705882
## 31               CD3+_%Linf     64.705882
## 32     CD27-CD57+CD3+_%Linf     64.705882
## 33      CD27-CD57+CD4+_%CD3     64.705882
## 34      CD27-CD57+CD8+_%CD3     64.705882
## 35                CD3_%Leuc     64.705882
## 36           CD3+CD4+_%Linf     64.705882
## 37          CD3+CD57+_%Linf     64.705882
## 38           CD3+CD8+_%Linf     64.705882
## 39   CD45RA+CCR7+CD3+_%Linf     64.705882
## 40     CD8+_term_efect_%CD3     64.705882
## 41       CD8_exhausted_%CD3     64.705882
## 42         CD4_TCR_ab+_%CD3     64.705882
## 43               CD4+_%Linf     64.705882
## 44        CD8+_TCR_ab+_%CD3     64.705882
## 45               CD8+_%Linf     64.705882
## 46           CD8+CD4+_%Linf     64.705882
## 47           CD8-CD4-_%Linf     64.705882
## 48         HLADR+CD3+_%Linf     64.705882
## 49                    Leuc%     64.705882
## 50                    Linf%     64.705882
## 51            TCR_ab+_%Linf     64.705882
## 52            TCR_gd+_%Linf     64.705882
## 53             gd_VD1+_%CD3     64.705882
## 54         gd_VD1+VD2+_%CD3     64.705882
## 55         gd_VD1-VD2-_%CD3     64.705882
## 56             gd_VD2+_%CD3     64.705882
## 57          CD25+CD4+_%Linf     61.764706
## 58         HLADR+Lin_C_Leuc     61.764706
## 59               mDC_C_Leuc     61.764706
## 60               pDC_C_Leuc     61.764706
## 61   CD4_Central_Mem_C_Linf     61.764706
## 62  CD4_Effector_Mem_C_Linf     61.764706
## 63         CD4_Naïve_C_Linf     61.764706
## 64         CD4_TEMRA_C_Linf     61.764706
## 65   CD8_Central_Mem_C_Linf     61.764706
## 66  CD8_Effector_Mem_C_Linf     61.764706
## 67         CD8_Naïve_C_Linf     61.764706
## 68         CD8_TEMRA_C_Linf     61.764706
## 69           mDC_CD16_C_mDC     61.764706
## 70           mDC_CD1c_C_mDC     61.764706
## 71         mDC_Clec9A_C_mDC     61.764706
## 72              CD3+_C_Linf     61.764706
## 73    CD27-CD57+CD3+_C_Linf     61.764706
## 74     CD27-CD57+CD4+_C_CD3     61.764706
## 75     CD27-CD57+CD8+_C_CD3     61.764706
## 76          CD3+CD4+_C_Linf     61.764706
## 77         CD3+CD57+_C_Linf     61.764706
## 78          CD3+CD8+_C_Linf     61.764706
## 79  CD45RA+CCR7+CD3+_C_Linf     61.764706
## 80    CD8+_term_efect_C_CD3     61.764706
## 81      CD8_exhausted_C_CD3     61.764706
## 82        CD4_TCR_ab+_C_CD3     61.764706
## 83              CD4+_C_Linf     61.764706
## 84       CD8+_TCR_ab+_C_CD3     61.764706
## 85              CD8+_C_Linf     61.764706
## 86          CD8+CD4+_C_Linf     61.764706
## 87          CD8-CD4-_C_Linf     61.764706
## 88        HLADR+CD3+_C_Linf     61.764706
## 89           TCR_ab+_C_Linf     61.764706
## 90           TCR_gd+_C_Linf     61.764706
## 91            gd_VD1+_C_CD3     61.764706
## 92        gd_VD1+VD2+_C_CD3     61.764706
## 93        gd_VD1-VD2-_C_CD3     61.764706
## 94            gd_VD2+_C_CD3     61.764706
## 95         CD25+CD4+_C_Linf     61.764706
## 96                    MOOSs     61.764706
## 97                     IL-6     58.823529
## 98                  IgM_CMV     55.882353
## 99                  IgG_CMV     55.882353
## 100                 Col_LDL     47.058824
## 101                  LDH_2C     47.058824
## 102                     MNA     47.058824
## 103                ansiedad     44.117647
## 104               depresion     44.117647
## 105                 Col_HDL     41.176471
## 106        Fecha_progresión     38.235294
## 107                 Num_pac     35.294118
## 108                  LDH_1C     35.294118
## 109               LDH_1eval     29.411765
## 110               LinfT_cel     26.470588
## 111                 LinfT_%     26.470588
## 112                 CD4_cel     26.470588
## 113                   CD4_%     26.470588
## 114                 CD8_cel     26.470588
## 115                   CD8_%     26.470588
## 116                 CD4:CD8     26.470588
## 117               LinfB_cel     26.470588
## 118                 LinfB_%     26.470588
## 119              LinfNK_cel     26.470588
## 120                LinfNK_%     26.470588
## 121                estudios     26.470588
## 122               est_civil     26.470588
## 123                     PCR     23.529412
## 124                   hogar     23.529412
## 125            segunda_eval     20.588235
## 126                 Prot_2C     11.764706
## 127                Tipo_tox     11.764706
## 128     Porcentaje_perdpeso      8.823529
## 129            p_peso_no_sí      8.823529
## 130                     LDH      8.823529
## 131                 Prot_1C      8.823529
## 132                  Alb_2C      8.823529
## 133                  PNI_2C      8.823529
## 134              Prot_1eval      8.823529
## 135               Hab_tabaq      5.882353
## 136                 Exp_tab      5.882353
## 137                  Alb_1C      5.882353
## 138                   Hb_2C      5.882353
## 139               Leucoc_2C      5.882353
## 140                Neutr_2C      5.882353
## 141                 Linf_2C      5.882353
## 142                 Plaq_2C      5.882353
## 143                  NLR_2C      5.882353
## 144          NLR2C_corte4o5      5.882353
## 145                  PLR_2C      5.882353
## 146                  SII_2C      5.882353
## 147            Tamaño_tumor      2.941176
## 148   Afectacion_ganglionar      2.941176
## 149  Afectacion_metastasica      2.941176
## 150               Col_total      2.941176
## 151                Prot_tot      2.941176
## 152                Albumina      2.941176
## 153                 PNI_pre      2.941176
## 154                 ALI_pre      2.941176
## 155            NLR1C_corte5      2.941176
## 156                  PNI_1C      2.941176
## 157                   Idpac      0.000000
## 158                    Sexo      0.000000
## 159                 Edad_dx      0.000000
## 160                 Anciano      0.000000
## 161                    ECOG      0.000000
## 162                    Peso      0.000000
## 163                   Talla      0.000000
## 164                     IMC      0.000000
## 165                Diabetes      0.000000
## 166                 Cardiop      0.000000
## 167              Enf_neurod      0.000000
## 168              Histologia      0.000000
## 169          Histología_num      0.000000
## 170                 Estadio      0.000000
## 171             Estadio_num      0.000000
## 172                   PD_L1      0.000000
## 173               Estatinas      0.000000
## 174                      Hb      0.000000
## 175              Leucoc_tot      0.000000
## 176             Neutrofilos      0.000000
## 177                Linf_tot      0.000000
## 178               Plaquetas      0.000000
## 179                 NLR_pre      0.000000
## 180                 PLR_pre      0.000000
## 181                 SII_pre      0.000000
## 182                   Hb_1C      0.000000
## 183               Leucoc_1C      0.000000
## 184                Neutr_1C      0.000000
## 185                 Linf_1C      0.000000
## 186                 Plaq_1C      0.000000
## 187                  NLR_1C      0.000000
## 188            NLR1C_corte4      0.000000
## 189                  PLR_1C      0.000000
## 190                  SII_1C      0.000000
## 191            primera_eval      0.000000
## 192        primera_eval_num      0.000000
## 193               Alb_1eval      0.000000
## 194                Hb_1eval      0.000000
## 195            Leucoc_1eval      0.000000
## 196             Neutr_1eval      0.000000
## 197              Linf_1eval      0.000000
## 198              Plaq_1eval      0.000000
## 199               NLR_1eval      0.000000
## 200               PLR_1eval      0.000000
## 201               PNI_1eval      0.000000
## 202               SII_1eval      0.000000
## 203              Mejor_resp      0.000000
## 204          Mejor_resp_num      0.000000
## 205                N_ciclos      0.000000
## 206               Toxicidad      0.000000
## 207               Grado_tox      0.000000
## 208           Interrupc_tto      0.000000
## 209            Motivo_inter      0.000000
## 210              Progresion      0.000000
## 211                  Exitus      0.000000
## 212                     SLP      0.000000
## 213                SLP_cens      0.000000
## 214                      SG      0.000000
## 215                 SG_cens      0.000000

Our limit is 23%, so we eliminate that variables that overcome the limit.

variables_a_eliminar <- tabla_faltantes %>%
  filter(Porcentaje_NA > 23) %>%
  pull(Columna)

df <- datos %>%
  select(-one_of(variables_a_eliminar))
tabla_faltantes = df %>%
  summarise(across(everything(), ~mean(is.na(.)))) %>%
  pivot_longer(everything(), names_to = "Columna", values_to = "Porcentaje_NA") %>%
  mutate(Porcentaje_NA = Porcentaje_NA * 100)
as.data.frame(tabla_faltantes[order(tabla_faltantes$Porcentaje_NA, decreasing = TRUE),])
##                   Columna Porcentaje_NA
## 1            segunda_eval     20.588235
## 2                 Prot_2C     11.764706
## 3                Tipo_tox     11.764706
## 4     Porcentaje_perdpeso      8.823529
## 5            p_peso_no_sí      8.823529
## 6                     LDH      8.823529
## 7                 Prot_1C      8.823529
## 8                  Alb_2C      8.823529
## 9                  PNI_2C      8.823529
## 10             Prot_1eval      8.823529
## 11              Hab_tabaq      5.882353
## 12                Exp_tab      5.882353
## 13                 Alb_1C      5.882353
## 14                  Hb_2C      5.882353
## 15              Leucoc_2C      5.882353
## 16               Neutr_2C      5.882353
## 17                Linf_2C      5.882353
## 18                Plaq_2C      5.882353
## 19                 NLR_2C      5.882353
## 20         NLR2C_corte4o5      5.882353
## 21                 PLR_2C      5.882353
## 22                 SII_2C      5.882353
## 23           Tamaño_tumor      2.941176
## 24  Afectacion_ganglionar      2.941176
## 25 Afectacion_metastasica      2.941176
## 26              Col_total      2.941176
## 27               Prot_tot      2.941176
## 28               Albumina      2.941176
## 29                PNI_pre      2.941176
## 30                ALI_pre      2.941176
## 31           NLR1C_corte5      2.941176
## 32                 PNI_1C      2.941176
## 33                  Idpac      0.000000
## 34                   Sexo      0.000000
## 35                Edad_dx      0.000000
## 36                Anciano      0.000000
## 37                   ECOG      0.000000
## 38                   Peso      0.000000
## 39                  Talla      0.000000
## 40                    IMC      0.000000
## 41               Diabetes      0.000000
## 42                Cardiop      0.000000
## 43             Enf_neurod      0.000000
## 44             Histologia      0.000000
## 45         Histología_num      0.000000
## 46                Estadio      0.000000
## 47            Estadio_num      0.000000
## 48                  PD_L1      0.000000
## 49              Estatinas      0.000000
## 50                     Hb      0.000000
## 51             Leucoc_tot      0.000000
## 52            Neutrofilos      0.000000
## 53               Linf_tot      0.000000
## 54              Plaquetas      0.000000
## 55                NLR_pre      0.000000
## 56                PLR_pre      0.000000
## 57                SII_pre      0.000000
## 58                  Hb_1C      0.000000
## 59              Leucoc_1C      0.000000
## 60               Neutr_1C      0.000000
## 61                Linf_1C      0.000000
## 62                Plaq_1C      0.000000
## 63                 NLR_1C      0.000000
## 64           NLR1C_corte4      0.000000
## 65                 PLR_1C      0.000000
## 66                 SII_1C      0.000000
## 67           primera_eval      0.000000
## 68       primera_eval_num      0.000000
## 69              Alb_1eval      0.000000
## 70               Hb_1eval      0.000000
## 71           Leucoc_1eval      0.000000
## 72            Neutr_1eval      0.000000
## 73             Linf_1eval      0.000000
## 74             Plaq_1eval      0.000000
## 75              NLR_1eval      0.000000
## 76              PLR_1eval      0.000000
## 77              PNI_1eval      0.000000
## 78              SII_1eval      0.000000
## 79             Mejor_resp      0.000000
## 80         Mejor_resp_num      0.000000
## 81               N_ciclos      0.000000
## 82              Toxicidad      0.000000
## 83              Grado_tox      0.000000
## 84          Interrupc_tto      0.000000
## 85           Motivo_inter      0.000000
## 86             Progresion      0.000000
## 87                 Exitus      0.000000
## 88                    SLP      0.000000
## 89               SLP_cens      0.000000
## 90                     SG      0.000000
## 91                SG_cens      0.000000

3 IMPUTATION:

We are going to use library mice.

tipos_var <- data.frame(Columna = names(df))
tipos_var$Tipo <- sapply(df, function(x) class(x)[1])
tipos_var
##                   Columna      Tipo
## 1                   Idpac character
## 2                    Sexo   numeric
## 3                 Edad_dx   numeric
## 4                 Anciano   numeric
## 5                    ECOG   numeric
## 6                    Peso   numeric
## 7                   Talla   numeric
## 8                     IMC   numeric
## 9     Porcentaje_perdpeso   numeric
## 10           p_peso_no_sí   numeric
## 11              Hab_tabaq   numeric
## 12                Exp_tab   numeric
## 13               Diabetes   numeric
## 14                Cardiop   numeric
## 15             Enf_neurod   numeric
## 16             Histologia character
## 17         Histología_num   numeric
## 18           Tamaño_tumor character
## 19  Afectacion_ganglionar character
## 20 Afectacion_metastasica character
## 21                Estadio character
## 22            Estadio_num   numeric
## 23                  PD_L1   numeric
## 24              Estatinas character
## 25              Col_total   numeric
## 26                    LDH   numeric
## 27               Prot_tot   numeric
## 28               Albumina   numeric
## 29                     Hb   numeric
## 30             Leucoc_tot   numeric
## 31            Neutrofilos   numeric
## 32               Linf_tot   numeric
## 33              Plaquetas   numeric
## 34                NLR_pre   numeric
## 35                PLR_pre   numeric
## 36                PNI_pre   numeric
## 37                ALI_pre   numeric
## 38                SII_pre   numeric
## 39                Prot_1C   numeric
## 40                 Alb_1C   numeric
## 41                  Hb_1C   numeric
## 42              Leucoc_1C   numeric
## 43               Neutr_1C   numeric
## 44                Linf_1C   numeric
## 45                Plaq_1C   numeric
## 46                 NLR_1C   numeric
## 47           NLR1C_corte4   numeric
## 48           NLR1C_corte5   numeric
## 49                 PLR_1C   numeric
## 50                 PNI_1C   numeric
## 51                 SII_1C   numeric
## 52                Prot_2C   numeric
## 53                 Alb_2C   numeric
## 54                  Hb_2C   numeric
## 55              Leucoc_2C   numeric
## 56               Neutr_2C   numeric
## 57                Linf_2C   numeric
## 58                Plaq_2C   numeric
## 59                 NLR_2C   numeric
## 60         NLR2C_corte4o5   numeric
## 61                 PLR_2C   numeric
## 62                 PNI_2C   numeric
## 63                 SII_2C   numeric
## 64           primera_eval character
## 65       primera_eval_num   numeric
## 66             Prot_1eval   numeric
## 67              Alb_1eval   numeric
## 68               Hb_1eval   numeric
## 69           Leucoc_1eval   numeric
## 70            Neutr_1eval   numeric
## 71             Linf_1eval   numeric
## 72             Plaq_1eval   numeric
## 73              NLR_1eval   numeric
## 74              PLR_1eval   numeric
## 75              PNI_1eval   numeric
## 76              SII_1eval   numeric
## 77             Mejor_resp character
## 78         Mejor_resp_num   numeric
## 79               N_ciclos   numeric
## 80              Toxicidad   numeric
## 81               Tipo_tox character
## 82              Grado_tox character
## 83          Interrupc_tto   numeric
## 84           Motivo_inter character
## 85             Progresion   numeric
## 86           segunda_eval   numeric
## 87                 Exitus   numeric
## 88                    SLP   numeric
## 89               SLP_cens   numeric
## 90                     SG   numeric
## 91                SG_cens   numeric

As we can see, we have both numerical and categorical variables, so we are interested in transforming these categorical variables into factors to be able to impute, even some numerical variables, through the mean method.

df$Idpac <- as.factor(df$Idpac)
df$Histologia <- as.factor(df$Histologia)
df$Tamaño_tumor <- as.factor(df$Tamaño_tumor)
df$Afectacion_ganglionar <- as.factor(df$Afectacion_ganglionar)
df$Afectacion_metastasica <- as.factor(df$Afectacion_metastasica)
df$Estadio <- as.factor(df$Estadio)
df$Estatinas <- as.factor(df$Estatinas)
df$primera_eval_num <- as.factor(df$primera_eval_num)
df$Mejor_resp_num <- as.factor(df$Mejor_resp_num)
df$Tipo_tox <- as.factor(df$Tipo_tox)
df$Grado_tox <- as.factor(df$Grado_tox)
df$Motivo_inter <- as.factor(df$Motivo_inter)
df$p_peso_no_sí <- as.factor(df$p_peso_no_sí)
df$Hab_tabaq <- as.factor(df$Hab_tabaq)
df$NLR1C_corte4 <- as.factor(df$NLR1C_corte4)
df$NLR1C_corte5 <- as.factor(df$NLR1C_corte5)
df$Histología_num <- as.factor(df$Histología_num)
df$Estadio_num <- as.factor(df$Estadio_num)
df$Toxicidad <- as.factor(df$Toxicidad)
df$Interrupc_tto <- as.factor(df$Interrupc_tto)
df$Enf_neurod <- as.factor(df$Enf_neurod)
df$Sexo <- as.factor(df$Sexo)
df$ECOG <- as.factor(df$ECOG)
df$Progresion <- as.factor(df$Progresion)
df$Cardiop <- as.factor(df$Cardiop)
df$Diabetes <- as.factor(df$Diabetes)
tipos_var2 <- data.frame(Columna = names(df))
tipos_var2$Tipo <- sapply(df, function(x) class(x)[1])
tipos_var2
##                   Columna      Tipo
## 1                   Idpac    factor
## 2                    Sexo    factor
## 3                 Edad_dx   numeric
## 4                 Anciano   numeric
## 5                    ECOG    factor
## 6                    Peso   numeric
## 7                   Talla   numeric
## 8                     IMC   numeric
## 9     Porcentaje_perdpeso   numeric
## 10           p_peso_no_sí    factor
## 11              Hab_tabaq    factor
## 12                Exp_tab   numeric
## 13               Diabetes    factor
## 14                Cardiop    factor
## 15             Enf_neurod    factor
## 16             Histologia    factor
## 17         Histología_num    factor
## 18           Tamaño_tumor    factor
## 19  Afectacion_ganglionar    factor
## 20 Afectacion_metastasica    factor
## 21                Estadio    factor
## 22            Estadio_num    factor
## 23                  PD_L1   numeric
## 24              Estatinas    factor
## 25              Col_total   numeric
## 26                    LDH   numeric
## 27               Prot_tot   numeric
## 28               Albumina   numeric
## 29                     Hb   numeric
## 30             Leucoc_tot   numeric
## 31            Neutrofilos   numeric
## 32               Linf_tot   numeric
## 33              Plaquetas   numeric
## 34                NLR_pre   numeric
## 35                PLR_pre   numeric
## 36                PNI_pre   numeric
## 37                ALI_pre   numeric
## 38                SII_pre   numeric
## 39                Prot_1C   numeric
## 40                 Alb_1C   numeric
## 41                  Hb_1C   numeric
## 42              Leucoc_1C   numeric
## 43               Neutr_1C   numeric
## 44                Linf_1C   numeric
## 45                Plaq_1C   numeric
## 46                 NLR_1C   numeric
## 47           NLR1C_corte4    factor
## 48           NLR1C_corte5    factor
## 49                 PLR_1C   numeric
## 50                 PNI_1C   numeric
## 51                 SII_1C   numeric
## 52                Prot_2C   numeric
## 53                 Alb_2C   numeric
## 54                  Hb_2C   numeric
## 55              Leucoc_2C   numeric
## 56               Neutr_2C   numeric
## 57                Linf_2C   numeric
## 58                Plaq_2C   numeric
## 59                 NLR_2C   numeric
## 60         NLR2C_corte4o5   numeric
## 61                 PLR_2C   numeric
## 62                 PNI_2C   numeric
## 63                 SII_2C   numeric
## 64           primera_eval character
## 65       primera_eval_num    factor
## 66             Prot_1eval   numeric
## 67              Alb_1eval   numeric
## 68               Hb_1eval   numeric
## 69           Leucoc_1eval   numeric
## 70            Neutr_1eval   numeric
## 71             Linf_1eval   numeric
## 72             Plaq_1eval   numeric
## 73              NLR_1eval   numeric
## 74              PLR_1eval   numeric
## 75              PNI_1eval   numeric
## 76              SII_1eval   numeric
## 77             Mejor_resp character
## 78         Mejor_resp_num    factor
## 79               N_ciclos   numeric
## 80              Toxicidad    factor
## 81               Tipo_tox    factor
## 82              Grado_tox    factor
## 83          Interrupc_tto    factor
## 84           Motivo_inter    factor
## 85             Progresion    factor
## 86           segunda_eval   numeric
## 87                 Exitus   numeric
## 88                    SLP   numeric
## 89               SLP_cens   numeric
## 90                     SG   numeric
## 91                SG_cens   numeric

We can see the distribution of missing values:

patrones = md.pattern(df, rotate.names = TRUE)

3.1 Mean method:

imputed_data1 <- mice(df %>% 
                        select(-Idpac,-Histologia,-Afectacion_ganglionar, -Afectacion_metastasica,-Estadio,-Estatinas,-primera_eval_num, -Mejor_resp_num,
                               -Tipo_tox, -Tamaño_tumor, -Grado_tox, -Motivo_inter, -p_peso_no_sí, -Hab_tabaq, -NLR1C_corte4, -NLR1C_corte5,-Histología_num,
                               -Estadio_num, -Toxicidad,-Interrupc_tto,-Enf_neurod,-Sexo,-ECOG, -Progresion, -Cardiop, -Diabetes),
                      method = "mean", print = FALSE)
## Warning: Number of logged events: 752
df_imputado1 <- complete(imputed_data1)
df_imputado1
##     Edad_dx Anciano  Peso Talla      IMC Porcentaje_perdpeso   Exp_tab PD_L1
## 1  46.00000       0  88.0  1.77 28.08899          0.04583871  20.00000   100
## 2  68.00000       0  85.0  1.55 35.37981          0.00000000   0.00000    70
## 3  59.00000       0  65.0  1.59 25.71101          0.00000000  45.00000    50
## 4  72.00000       1  88.5  1.77 28.24859          0.00000000  92.00000     2
## 5  50.00000       0  90.0  1.76 29.05475          0.10000000  55.00000    60
## 6  71.00000       1  76.6  1.63 28.83059          0.00000000 200.00000    90
## 7  71.00000       1  67.0  1.50 29.77778          0.07600000  60.00000   100
## 8  79.00000       1  67.0  1.61 25.84777          0.00000000  40.00000    70
## 9  73.14168       1  63.0  1.68 22.32143          0.04583871  50.00000    90
## 10 68.51745       0  77.5  1.81 23.65618          0.00000000  50.00000    70
## 11 56.48734       0  73.8  1.75 24.09796          0.04583871  36.00000    80
## 12 66.27242       0  66.3  1.63 24.95389          0.22900000  50.00000    50
## 13 61.96304       0  63.8  1.56 26.21631          0.13800000   0.00000    80
## 14 64.45996       0  65.0  1.79 20.28651          0.11000000  50.00000   100
## 15 58.70500       0  53.0  1.55 22.06035          0.00000000  25.00000    95
## 16 60.30664       0  72.0  1.71 24.62296          0.00000000  82.00000    90
## 17 63.00000       0  67.0  1.50 29.77778          0.00000000  60.00000   100
## 18 82.00000       1  61.0  1.63 22.95909          0.00000000 100.00000    90
## 19 66.00000       0  64.2  1.61 24.76756          0.00000000  50.00000    60
## 20 50.00000       0  55.0  1.63 20.70082          0.00000000  51.65625   100
## 21 78.00000       1  69.0  1.55 28.72008          0.06700000  75.00000    70
## 22 73.00000       1 102.0  1.91 27.95976          0.01000000  83.00000    70
## 23 60.00000       0  67.0  1.73 22.38631          0.13000000  40.00000   100
## 24 70.00000       1  64.7  1.60 25.27344          0.03000000  51.65625    90
## 25 64.00000       0  47.0  1.60 18.35937          0.03100000  40.00000    70
## 26 57.00000       0  61.0  1.62 23.24341          0.04000000  30.00000    70
## 27 71.00000       1  52.0  1.56 21.36752          0.05500000   0.00000    80
## 28 75.00000       1  62.0  1.60 24.21875          0.08800000  25.00000   100
## 29 68.00000       0  75.0  1.68 26.57313          0.03800000  40.00000    90
## 30 62.00000       0  80.0  1.72 27.04164          0.00000000  60.00000    90
## 31 51.00000       0  62.0  1.81 18.92494          0.07500000  45.00000    60
## 32 80.00000       1  53.0  1.58 21.23057          0.15900000  40.00000    80
## 33 65.00000       0  85.0  1.65 31.22130          0.04500000  85.00000    95
## 34 62.00000       0  97.0  1.65 35.62902          0.00000000  25.00000    70
##    Col_total       LDH Prot_tot Albumina   Hb Leucoc_tot Neutrofilos Linf_tot
## 1   217.0000  163.0000 7.000000 4.100000 15.3      10100        8000     1400
## 2   154.0000  171.0000 6.000000 3.700000 11.8       9800        8200      800
## 3   146.0000  197.0000 7.200000 4.300000 16.7       9900        7400     1400
## 4   149.0000  159.0000 7.100000 4.000000 14.6       5600        3000     1800
## 5   210.0000  198.0000 7.900000 4.400000 15.7       8900        5300     2300
## 6   162.0000  220.0000 8.000000 4.300000 13.1       8800        6000     1600
## 7   142.0000  198.0000 6.400000 3.600000 11.5      10000        9000      400
## 8   167.0000  184.0000 7.000000 3.900000 12.3       7700        5300     1600
## 9   153.0000  176.0000 6.900000 3.700000 12.9      16200       13200     1900
## 10  132.0000  199.0000 7.300000 4.000000 13.0      15700       13400     1400
## 11  113.0000  190.0000 7.300000 3.500000 13.6      10600        8000     1500
## 12  182.0000  198.0000 6.500000 3.700000 11.4       8700        5000     2500
## 13  242.0000  184.0000 7.300000 4.100000 13.7      12600        8700     2200
## 14  133.0000  183.0000 7.000000 4.100000 13.7      11400        7600     2300
## 15  215.0000  204.0000 7.200000 4.400000 11.9      13400        9400     2900
## 16  202.0000  276.0000 5.600000 3.200000 15.5      13100       12300      500
## 17  262.0000  201.0000 5.400000 2.800000 11.6       4100        2500      800
## 18  200.0000  383.0000 8.900000 3.900000 12.1      11700        7100     2700
## 19  199.0000  382.0000 6.300000 3.700000 10.6       4000        2600      900
## 20  194.0000  156.0000 7.300000 4.300000 11.5      10800        9400      500
## 21  176.0000  175.0000 7.100000 4.300000 11.5      10600        7300     1200
## 22  160.0000  195.0000 7.300000 4.100000 12.6       7700        4800     1900
## 23  111.0000  326.0000 6.400000 3.000000 13.5       6800        5400      700
## 24  276.0000  263.6452 7.000000 3.900000 14.1       6000        3500     2000
## 25  155.0000 1644.0000 6.900000 3.400000 10.9      13800        8700     3000
## 26  197.0000  279.0000 6.900000 4.400000 13.0       6300        4300     1100
## 27  206.0000  164.0000 6.600000 4.000000 14.0       6200        4800      800
## 28  208.0000  222.0000 7.400000 4.100000 12.4       7200        4900     1500
## 29  191.0000  267.0000 6.900000 3.500000 14.5      20500       11500     3300
## 30  201.0000  248.0000 7.300000 4.200000 13.6      14100        8400     3500
## 31  142.0000  263.6452 7.100000 3.900000 12.8       9600        7100     1300
## 32  187.4545  263.6452 7.006061 3.912121 12.6       7600        5300     1300
## 33  192.0000  230.0000 7.700000 4.400000 15.3       8400        5400     1800
## 34  397.0000  201.0000 7.000000 4.200000 14.2      12500       10700     1300
##    Plaquetas   NLR_pre   PLR_pre  PNI_pre   ALI_pre   SII_pre  Prot_1C  Alb_1C
## 1     273000  5.714286 195.00000 48.00000 20.153851 1560000.0 7.500000 4.60000
## 2     124000 10.250000 155.00000 41.00000 12.771249 1271000.0 6.200000 3.90000
## 3     349000  5.285714 249.28571 50.00000 20.916253 1844714.3 7.200000 4.40000
## 4     220000  1.666667 122.22222 49.00000 67.796610  366666.7 7.048387 3.90625
## 5     350000  2.304348 152.17391 55.50000 55.478130  806521.7 7.400000 4.50000
## 6     279000  3.750000 174.37500 51.00000 33.059079 1046250.0 8.100000 4.20000
## 7     269000 22.500000 672.50000 38.00000  4.764444 6052500.0 6.500000 4.00000
## 8     201000  3.312500 125.62500 47.00000 30.432089  665812.5 7.700000 4.00000
## 9     317000  6.947368 166.84211 46.50000 11.887852 2202315.8 7.048387 3.90000
## 10    324000  9.571429 231.42857 47.00000  9.886163 3101142.9 7.400000 4.00000
## 11    489000  5.333333 326.00000 42.50000 15.814286 2608000.0 7.000000 3.40000
## 12    216000  2.000000  86.40000 49.50000 46.164703  432000.0 7.100000 4.10000
## 13    455000  3.954545 206.81818 52.00000 27.180583 1799318.2 7.300000 4.00000
## 14    274000  3.304348 119.13043 52.50000 25.171285  905391.3 7.000000 3.70000
## 15    208000  3.241379  71.72414 58.50000 29.945757  674206.9 6.900000 3.70000
## 16    112000 24.600000 224.00000 34.50000  3.202987 2755200.0 7.800000 4.20000
## 17    293000  3.125000 366.25000 32.00000 26.680889  915625.0 4.600000 3.10000
## 18    358000  2.629630 132.59259 52.50000 34.050591  941407.4 9.100000 4.00000
## 19    338000  2.888889 375.55556 41.50000 31.721533  976444.4 6.000000 3.10000
## 20    464000 18.800000 928.00000 45.50000  4.734761 8723200.0 8.000000 4.50000
## 21    158000  6.083333 131.66667 49.00000 20.300771  961166.7 7.200000 4.20000
## 22    248000  2.526316 130.52632 50.50000 45.376360  626526.3 7.300000 3.80000
## 23    335000  7.714286 478.57143 33.50000  8.705789 2584285.7 6.800000 3.60000
## 24    143000  1.750000  71.50000 49.00000 56.323661  250250.0 7.400000 3.90000
## 25    709000  2.900000 236.33333 49.00000 21.524784 2056100.0 7.300000 3.60000
## 26    287000  3.909091 260.90909 49.50000 26.162348 1121909.1 6.400000 3.70000
## 27    295000  6.000000 368.75000 44.00000 14.245014 1770000.0 6.900000 4.10000
## 28    228000  3.266667 152.00000 48.50000 30.397003  744800.0 7.100000 4.00000
## 29    271000  3.484848  82.12121 51.50000 26.688665  944393.9 6.800000 3.30000
## 30    461000  2.400000 131.71429 59.50000 47.322877 1106400.0 6.300000 3.80000
## 31    327000  5.461538 251.53846 45.50000 13.514007 1785923.1 6.500000 3.30000
## 32    249000  4.076923 191.53846 47.42424 26.858982 1015153.8 7.100000 4.30000
## 33    306000  3.000000 170.00000 53.00000 45.791246  918000.0 7.048387 3.90625
## 34    234000  8.230769 180.00000 48.50000 18.180788 1926000.0 6.600000 4.10000
##    Hb_1C Leucoc_1C Neutr_1C Linf_1C Plaq_1C    NLR_1C    PLR_1C   PNI_1C
## 1   15.9      8100     6000    1600  369000  3.750000 230.62500 54.00000
## 2   11.7      8500     7000     800  112000  8.750000 140.00000 43.00000
## 3   16.1     12000     8000    2500  382000  3.200000 152.80000 56.50000
## 4   15.5      7300     4400    2000  266000  2.200000 133.00000 10.00000
## 5   15.9      9200     4900    3100  364000  1.580645 117.41935 60.50000
## 6   14.5      8000     5300    1600  293000  3.312500 183.12500 50.00000
## 7   11.6      4500     3200     900  218000  3.555556 242.22222 44.50000
## 8   12.1      3600     1900     900  131000  2.111111 145.55556 44.50000
## 9   14.5     16100    12100    2900  380000  4.172414 131.03448 53.50000
## 10  13.5     12800     9800    1900  214000  5.157895 112.63158 49.50000
## 11  11.4     12500    10400    1000  463000 10.400000 463.00000 39.00000
## 12  11.6      7600     3700    2900  242000  1.275862  83.44828 55.50000
## 13  14.3     11300     6200    3600  452000  1.722222 125.55556 58.00000
## 14  10.8     15400    11300    2500  444000  4.520000 177.60000 49.50000
## 15  11.3     10400     8400    1000  272000  8.400000 272.00000 42.00000
## 16  13.7     14100     9700    3100  494000  3.129032 159.35484 57.50000
## 17   8.4      4800     3300     700  226000  4.714286 322.85714 34.50000
## 18  11.9     11100     6000    3000  380000  2.000000 126.66667 55.00000
## 19  11.1      3600     1700    1100  338000  1.545455 307.27273 36.50000
## 20  11.9     10900     8900    1200  465000  7.416667 387.50000 51.00000
## 21  10.2     13800     9300    1600  205000  5.812500 128.12500 50.00000
## 22  12.5      7400     4600    1800  304000  2.555556 168.88889 47.00000
## 23  16.0      4600     3000    1100  274000  2.727273 249.09091 41.50000
## 24  12.9      6000     3000    2200  277000  1.363636 125.90909 50.00000
## 25  11.1     12600     7000    3600  650000  1.944444 180.55556 54.00000
## 26  11.7      9000     6300     800  457000  7.875000 571.25000 41.00000
## 27  13.6      4900     2700    1600  192000  1.687500 120.00000 49.00000
## 28  11.7      6900     5900     600  259000  9.833333 431.66667 43.00000
## 29  14.5     12800     6800    2800  366000  2.428571 130.71429 47.00000
## 30  11.6      8700     4600    2200  553000  2.090909 251.36364 49.00000
## 31  10.5      9000     6300    1200  513000  5.250000 427.50000 39.00000
## 32  13.2     13100     8700    2900  345000  3.000000 118.96552 57.50000
## 33  15.6     10000     6800    2000  323000  3.400000 161.50000 47.33333
## 34  15.4     10200     7600    1700  208000  4.470588 122.35294 49.50000
##       SII_1C  Prot_2C   Alb_2C    Hb_2C Leucoc_2C  Neutr_2C  Linf_2C  Plaq_2C
## 1  1383750.0 7.900000 4.500000 16.50000   6400.00  3400.000 2300.000 253000.0
## 2   980000.0 6.100000 3.700000 11.40000   8300.00  6200.000 1200.000 126000.0
## 3  1222400.0 7.200000 4.400000 16.70000   8400.00  4500.000 3000.000 329000.0
## 4   585200.0 7.200000 4.100000 15.30000   7200.00  4300.000 1900.000 254000.0
## 5   575354.8 8.000000 4.500000 16.30000   9200.00  5100.000 2800.000 313000.0
## 6   970562.5 8.100000 4.500000 15.50000   8000.00  5300.000 1800.000    285.0
## 7   775111.1 7.200000 4.100000 12.40000   8200.00  6400.000 1100.000 265000.0
## 8   276555.6 7.223333 4.012903 13.15312   9106.25  5796.875 2090.625 305883.9
## 9  1585517.2 7.223333 3.700000 13.40000  19400.00 16100.000 2300.000 406000.0
## 10 1103789.5 7.500000 4.100000 13.40000   8700.00  5500.000 2200.000 226000.0
## 11 4815200.0 6.500000 2.900000  8.60000  14500.00 12100.000 1200.000 858000.0
## 12  308758.6 6.800000 3.900000 11.40000   9400.00  4400.000 3100.000 260000.0
## 13  778444.4 7.100000 4.200000 15.00000  10200.00  5100.000 2900.000 319000.0
## 14 2006880.0 7.200000 4.000000 10.90000  14700.00  9900.000 3500.000 408000.0
## 15 2284800.0 7.200000 3.900000 11.20000  10600.00  7900.000 1400.000 254000.0
## 16 1545741.9 7.200000 3.900000 13.30000   9900.00  6100.000 2500.000 297000.0
## 17 1065428.6 5.300000 3.000000 10.30000   3800.00  2300.000  800.000 218000.0
## 18  760000.0 8.800000 4.100000 12.90000  11200.00  6100.000 3300.000 272000.0
## 19  522363.6 6.700000 3.700000 11.60000   4000.00  1800.000 1500.000 394000.0
## 20 3448750.0 7.900000 4.600000 12.30000   8600.00  6300.000 1200.000 425000.0
## 21 1191562.5 6.900000 4.400000 10.40000  12500.00  8500.000 1500.000 217000.0
## 22  776888.9 7.700000 3.900000 13.40000   6400.00  3600.000 1800.000 194000.0
## 23  747272.7 7.800000 3.600000 15.80000   5400.00  3700.000 1000.000 237000.0
## 24  377727.3 7.400000 4.000000 13.20000   5100.00  2400.000 2100.000 240000.0
## 25 1263888.9 7.500000 3.800000 11.40000  13900.00  7900.000 3900.000 615000.0
## 26 3598875.0 7.223333 4.012903 13.15312   9106.25  5796.875 2090.625 305883.9
## 27  324000.0 6.800000 4.200000 13.50000   5300.00  3300.000 1400.000 235000.0
## 28 2546833.3 7.100000 4.000000 11.70000   6900.00  5900.000  600.000 259000.0
## 29  888857.1 7.500000 3.700000 13.80000  12000.00  5700.000 4000.000 256000.0
## 30 1156272.7 6.300000 4.100000 13.00000   8300.00  4100.000 2900.000 343000.0
## 31 2693250.0 7.223333 4.012903 11.40000   7600.00  4900.000 1300.000 412000.0
## 32 1035000.0 7.500000 4.500000 12.90000   8800.00  5800.000 1800.000 337000.0
## 33 1098200.0 7.700000 4.300000 15.70000   9600.00  5900.000 2200.000 312000.0
## 34  929882.4 6.600000 4.100000 16.30000   8900.00  5000.000 2400.000 254000.0
##       NLR_2C NLR2C_corte4o5      PLR_2C   PNI_2C       SII_2C primera_eval
## 1   1.478261           0.00 110.0000000 56.50000  374000.0000           EE
## 2   5.166667           1.00 105.0000000 43.00000  651000.0000           RP
## 3   1.500000           0.00 109.6666667 59.00000  493500.0000           RP
## 4   2.263158           0.00 133.6842105 50.50000  574842.1053           PS
## 5   1.821429           0.00 111.7857143 59.00000  570107.1429           EE
## 6   2.944444           0.00   0.1583333 54.00000     839.1667           RP
## 7   5.818182           1.00 240.9090909 46.50000 1541818.1818           EE
## 8   3.348731           0.25 177.5906414 50.70968 1134689.6890           RP
## 9   7.000000           1.00 176.5217391 48.50000 2842000.0000           EE
## 10  2.500000           0.00 102.7272727 52.00000  565000.0000           RP
## 11 10.083333           1.00 715.0000000 35.00000 8651500.0000           PE
## 12  1.419355           0.00  83.8709677 54.50000  369032.2581           EE
## 13  1.758621           0.00 110.0000000 56.50000  561000.0000           RP
## 14  2.828571           0.00 116.5714286 57.50000 1154057.1429           EE
## 15  5.642857           1.00 181.4285714 46.00000 1433285.7143           EE
## 16  2.440000           0.00 118.8000000 51.50000  724680.0000           RP
## 17  2.875000           0.00 272.5000000 34.00000  626750.0000           EE
## 18  1.848485           0.00  82.4242424 57.50000  502787.8788           RP
## 19  1.200000           0.00 262.6666667 44.50000  472800.0000           RP
## 20  5.250000           1.00 354.1666667 52.00000 2231250.0000           EE
## 21  5.666667           1.00 144.6666667 51.50000 1229666.6667           PE
## 22  2.000000           0.00 107.7777778 48.00000  388000.0000           EE
## 23  3.700000           0.00 237.0000000 41.00000  876900.0000           RP
## 24  1.142857           0.00 114.2857143 50.50000  274285.7143           EE
## 25  2.025641           0.00 157.6923077 57.50000 1245769.2308           EE
## 26  3.348731           0.25 177.5906414 50.70968 1134689.6890           PE
## 27  2.357143           0.00 167.8571429 49.00000  553928.5714           RP
## 28  9.833333           1.00 431.6666667 43.00000 2546833.3333           PE
## 29  1.425000           0.00  64.0000000 57.00000  364800.0000           EE
## 30  1.413793           0.00 118.2758621 55.50000  484931.0345           EE
## 31  3.769231           0.00 316.9230769 50.70968 1552923.0769           PE
## 32  3.222222           0.00 187.2222222 54.00000 1085888.8889           RP
## 33  2.681818           0.00 141.8181818 54.00000  836727.2727           RP
## 34  2.083333           0.00 105.8333333 53.00000  529166.6667           EE
##    Prot_1eval Alb_1eval Hb_1eval Leucoc_1eval Neutr_1eval Linf_1eval Plaq_1eval
## 1    7.300000       4.4     16.9         8000        5300       2100     262000
## 2    6.000000       3.9     11.2         7500        5500       1300      96000
## 3    7.100000       4.5     16.6         8700        4900       2900     315000
## 4    7.200000       4.0     15.7         7800        4400       2500     259000
## 5    7.087097       4.3     16.5         8700        4600       2800     285000
## 6    7.600000       4.4     15.4         8000        5900       1400     263000
## 7    6.700000       3.9     11.1         7600        6000       1000     229000
## 8    6.400000       4.2     11.6         8600        6300       1400     124000
## 9    6.900000       3.7     12.9        16200       13200       1900     317000
## 10   7.700000       4.5     14.6         7400        4700       1900     219000
## 11   7.000000       3.1      8.8        10200        9100        500     527000
## 12   7.200000       4.0     10.8        11100        7200       2600     227000
## 13   7.100000       4.2     15.1         9100        5000       2900     308000
## 14   8.000000       4.5     12.9        18400       13600       3200     328000
## 15   7.087097       3.8     11.3         9400        7200        900     309000
## 16   7.000000       4.1     15.8         9800        6000       2600     205000
## 17   5.500000       3.6     13.7         4600        2600       1100     220000
## 18   8.500000       4.1     12.7        10200        5400       3100     282000
## 19   7.100000       3.9     12.2         3100        1400       1300     290000
## 20   7.300000       3.7     12.5         9200        7100       1100     400000
## 21   6.400000       3.9      9.9        10000        7500        800     216000
## 22   7.700000       3.9     13.4         6400        3600       1800     194000
## 23   7.087097       3.1     14.9         4500        2900       1000     220000
## 24   7.700000       4.1     13.8         4300        2200       1600     234000
## 25   7.800000       3.9     11.8        13900        7700       4000     647000
## 26   6.400000       3.7     11.7         9000        6300        800     457000
## 27   7.000000       4.2     13.8         4600        3100       1100     257000
## 28   7.100000       4.0     11.7         6900        5900        600     259000
## 29   6.900000       3.9     14.5         9100        4200       3500     199000
## 30   6.300000       4.1     13.0         8300        4100       2900     343000
## 31   7.000000       4.0     11.3         7300        4300       1800     353000
## 32   7.700000       4.6     12.9         9700        6500       2100     308000
## 33   7.500000       4.3     15.9         8700        6000       1600     320000
## 34   6.600000       4.1     16.3         8900        5000       2400     254000
##    NLR_1eval  PLR_1eval PNI_1eval SII_1eval Mejor_resp N_ciclos segunda_eval
## 1   2.523810  124.76190      54.5  661238.1         RC       35    0.5185185
## 2   4.230769   73.84615      45.5  406153.8         RC       35    0.0000000
## 3   1.689655  108.62069      59.5  532241.4         RP        7    0.0000000
## 4   1.760000  103.60000      52.5  455840.0         EE       11    1.0000000
## 5   1.642857  101.78571      57.0  468214.3         EE        7    1.0000000
## 6   4.214286  187.85714      51.0 1108357.1         RC        4    0.5185185
## 7   6.000000  229.00000      44.0 1374000.0         RP       19    1.0000000
## 8   4.500000   88.57143      49.0  558000.0         RP        1    0.0000000
## 9   6.947368  166.84211      46.5 2202315.8         EE        3    0.0000000
## 10  2.473684  115.26316      54.5  541736.8         RP       26    0.0000000
## 11 18.200000 1054.00000      33.5 9591400.0         PE        3    1.0000000
## 12  2.769231   87.30769      53.0  628615.4         RP        5    0.0000000
## 13  1.724138  106.20690      56.5  531034.5         RP       11    1.0000000
## 14  4.250000  102.50000      61.0 1394000.0         EE        6    0.0000000
## 15  8.000000  343.33333      42.5 2472000.0         EE        6    1.0000000
## 16  2.307692   78.84615      54.0  473076.9         RP       32    1.0000000
## 17  2.363636  200.00000      41.5  520000.0         RP       25    0.5185185
## 18  1.741935   90.96774      56.5  491225.8         RP       35    0.5185185
## 19  1.076923  223.07692      45.5  312307.7         RP       16    0.0000000
## 20  6.454545  363.63636      42.5 2581818.2         RC       25    0.0000000
## 21  9.375000  270.00000      43.0 2025000.0         PE        3    0.0000000
## 22  2.000000  107.77778      48.0  388000.0         RP        5    1.0000000
## 23  2.900000  220.00000      36.0  638000.0         RP        8    0.5185185
## 24  1.375000  146.25000      49.0  321750.0         EE        8    1.0000000
## 25  1.925000  161.75000      59.0 1245475.0         EE        8    1.0000000
## 26  7.875000  571.25000      41.0 3598875.0         PE        1    1.0000000
## 27  2.818182  233.63636      47.5  724272.7         RC       35    0.0000000
## 28  9.833333  431.66667      43.0 2546833.3         PE        2    0.0000000
## 29  1.200000   56.85714      56.5  238800.0         RP       27    0.0000000
## 30  1.413793  118.27586      55.5  484931.0         RP       13    1.0000000
## 31  2.388889  196.11111      49.0  843277.8         PE        4    1.0000000
## 32  3.095238  146.66667      56.5  953333.3         RP       35    0.5185185
## 33  3.750000  200.00000      51.0 1200000.0         RP       23    1.0000000
## 34  2.083333  105.83333      53.0  529166.7         RP       35    0.5185185
##    Exitus        SLP SLP_cens        SG SG_cens
## 1       1 29.8644764        1 29.864476       1
## 2       0 60.3860370        1 60.386037       1
## 3       0 35.1868583        0 57.626283       1
## 4       1  7.3921971        0 33.741273       0
## 5       1  4.5010267        0 18.825462       0
## 6       0 41.4948665        1 41.494867       1
## 7       1 24.0164271        0 30.225873       0
## 8       1  7.8850103        1  7.885010       1
## 9       1  1.8069815        0  1.806982       0
## 10      1 19.9425051        1 19.942505       0
## 11      1  1.8726899        0 17.478439       0
## 12      1 40.7392197        1 40.739220       0
## 13      1  7.4579055        0 41.002053       0
## 14      1  5.6509240        0  8.837782       0
## 15      1  3.6796715        0  6.570842       0
## 16      1 22.3737166        0 28.747433       0
## 17      1 21.9794661        1 21.979466       0
## 18      0 46.3244353        1 46.324435       1
## 19      0 35.3182752        0 35.318275       1
## 20      0 45.6344969        1 45.634497       1
## 21      1  1.9055441        0  5.749487       0
## 22      1  7.2607803        0 22.078029       0
## 23      1  9.3305955        1  9.330595       0
## 24      1  7.1293634        0 16.131417       0
## 25      0  5.6180698        0 10.611910       0
## 26      1  0.7556468        0 41.166324       0
## 27      0 31.1457906        1 31.145791       1
## 28      1  1.3798768        0  1.839836       0
## 29      1 17.8069815        0 26.579055       0
## 30      1 11.1704312        0 22.702259       0
## 31      1  1.8069815        0 16.000000       0
## 32      0 40.2135524        1 40.213552       1
## 33      1 16.1642710        0 35.778234       0
## 34      0 39.4579055        1 39.457906       1
df_imputado1$Edad_dx <- round(df_imputado1$Edad_dx, 0)
df_imputado1$LDH <- round(df_imputado1$LDH, 0)
df_imputado1$LDH <- round(df_imputado1$LDH, 0)
df_imputado1$Exp_tab <- round(df_imputado1$Exp_tab, 0)
df_imputado1$Col_total <- round(df_imputado1$Col_total, 0)
df_imputado1$Leucoc_1C <- round(df_imputado1$Leucoc_1C, 0)
df_imputado1$Neutr_1C <- round(df_imputado1$Neutr_1C, 0)
df_imputado1$Linf_1C <- round(df_imputado1$Linf_1C, 0)
df_imputado1$Plaq_1C <- round(df_imputado1$Plaq_1C, 0)

df_imputado1$Prot_1C <- round(df_imputado1$Prot_1C, 1)
df_imputado1$Alb_1C <- round(df_imputado1$Alb_1C, 1)
df_imputado1$Hb_1C <- round(df_imputado1$Hb_1C, 1)
df_imputado1$Prot_tot <- round(df_imputado1$Prot_tot, 1)
df_imputado1$Albumina <- round(df_imputado1$Albumina, 1)

df_imputado1$Porcentaje_perdpeso <- round(df_imputado1$Porcentaje_perdpeso, 4)

df_imputado1$NLR_pre <- round(df_imputado1$NLR_pre, 2)
df_imputado1$PLR_pre <- round(df_imputado1$PLR_pre, 2)
df_imputado1$PNI_pre <- round(df_imputado1$PNI_pre, 2)
df_imputado1$ALI_pre <- round(df_imputado1$ALI_pre, 2)
df_imputado1$SII_pre <- round(df_imputado1$SII_pre, 2)
df_imputado1$NLR_1C <- round(df_imputado1$NLR_1C, 2)
df_imputado1$PLR_2C <- round(df_imputado1$PLR_2C, 2)
df_imputado1$SII_2C <- round(df_imputado1$SII_2C, 2)

3.2 Cart method:

imputed_data2 <- mice(df %>% 
                        select(Idpac,Histologia,Afectacion_ganglionar,Afectacion_metastasica,Estadio,Estatinas,primera_eval_num,Mejor_resp_num,Tipo_tox,
                               Tamaño_tumor,Grado_tox,Motivo_inter, NLR1C_corte4, NLR1C_corte5, Histología_num, Estadio_num, Toxicidad,Interrupc_tto,
                               Enf_neurod,Sexo, ECOG, Progresion, Cardiop, Diabetes),
                      method = "cart", print = FALSE)
## Warning: Number of logged events: 150
df_imputado2 <- complete(imputed_data2)
df_imputado2
##    Idpac         Histologia Afectacion_ganglionar Afectacion_metastasica
## 1   P_01     Adenocarcinoma                     2                     1c
## 2   P_02              Otros                     2                     1c
## 3   P_03     Adenocarcinoma                     1                     1c
## 4   P_04           Escamoso                     2                      0
## 5   P_05           Escamoso                     2                     1a
## 6   P_06              Otros                     3                     1c
## 7   P_07           Escamoso                     2                     1c
## 8   P_08           Escamoso                     2                      0
## 9   P_09           Escamoso                     2                      0
## 10  P_10     Adenocarcinoma                     2                     1c
## 11  P_11     Adenocarcinoma                     3                     1c
## 12  P_12     Adenocarcinoma                     1                     1b
## 13  P_13     Adenocarcinoma                     3                     1a
## 14  P_14              Otros                     0                     1b
## 15  P_15     Adenocarcinoma                     0                     1c
## 16  P_16     Adenocarcinoma                     2                     1b
## 17  P_18     Adenocarcinoma                     2                     1c
## 18  P_19     Adenocarcinoma                     3                     1c
## 19  P_20 Ca. indiferenciado                     2                     1c
## 20  P_22     Adenocarcinoma                     x                     1a
## 21  P_23     Adenocarcinoma                     0                     1c
## 22  P_24           Escamoso                     2                     1c
## 23  P_25     Adenocarcinoma                     3                     1c
## 24  P_26     Adenocarcinoma                     2                     1c
## 25  P_27     Adenocarcinoma                     3                     1c
## 26  P_28     Adenocarcinoma                     3                     1c
## 27  P_29              Otros                     3                     1b
## 28  P_30     Adenocarcinoma                     3                     1b
## 29  P_31     Adenocarcinoma                     2                     1a
## 30  P_32     Adenocarcinoma                     3                     1c
## 31  P_33     Adenocarcinoma                     2                     1b
## 32  P_34              Otros                     3                      0
## 33  P_35     Adenocarcinoma                     2                     1c
## 34  P_36     Adenocarcinoma                     0                     1c
##    Estadio   Estatinas primera_eval_num Mejor_resp_num              Tipo_tox
## 1      IVB           0                2              0           Miocarditis
## 2      IVB           0                1              0            Dermatitis
## 3      IVB           1                1              1             Hepatitis
## 4     IIIB           1                2              2                     0
## 5      IVA           0                2              2                     0
## 6      IVB           0                1              0               Uveítis
## 7      IVB           1                2              1            Neumonitis
## 8     IIIA           0                1              1             Hepatitis
## 9     IIIB           1                2              2                     0
## 10     IVB           0                1              1               Uveítis
## 11     IVB           0                3              3                     0
## 12     IVA           1                2              1            Neumonitis
## 13     IVA           0                1              1 Queratitis/Dermatitis
## 14     IVA           0                2              2                     0
## 15     IVB           0                2              2            Dermatitis
## 16     IVB           0                1              1              Artritis
## 17     IVB           0                2              1                     0
## 18     IVB           0                1              1            Tiroiditis
## 19     IVB           0                1              1           Encefalitis
## 20     IVA           0                1              0            Neumonitis
## 21     IVB           1                3              3                     0
## 22     IVB           0                2              1            Neumonitis
## 23     IVB           0                1              1                     0
## 24     IVB           0                2              2                     0
## 25     IVB 0 (fibrato)                1              1                     0
## 26     IVB           1                3              3                     0
## 27     IVB           0                1              0            Tiroiditis
## 28     IVB           0                3              3                     0
## 29     IVA           0                3              2            Dermatitis
## 30     IVB           0                2              1            Dermatitis
## 31     IVB           0                3              3                     0
## 32    IIIC           1                1              1                     0
## 33     IVB           1                1              1                     0
## 34     IVB           0                2              1              Artritis
##    Tamaño_tumor Grado_tox                 Motivo_inter NLR1C_corte4
## 1            2b         3 Fin del tratamiento previsto            0
## 2             X         1 Fin del tratamiento previsto            1
## 3            2b         3                    Toxicidad            0
## 4             4         0                   Progresión            0
## 5            2a         0                   Progresión            0
## 6             x         2                    Toxicidad            0
## 7             3         3                    Toxicidad            0
## 8            1c         3                    Toxicidad            0
## 9             4         0                       Exitus            1
## 10            3         1          Exitus (otra causa)            1
## 11            4         0                   Progresión            1
## 12           2b         3                    Toxicidad            0
## 13            4         1                   Progresión            0
## 14            x         0                   Progresión            1
## 15            4         1                   Progresión            1
## 16            x         1                   Progresión            0
## 17           2b         0          Exitus (otra causa)            1
## 18            4         1 Fin del tratamiento previsto            0
## 19            4         3                    Toxicidad            0
## 20            x         2                    Toxicidad            1
## 21            3         0                   Progresión            1
## 22            3         3                    Toxicidad            0
## 23            3         0    2º tumor/ hepatocarcinoma            0
## 24            4         0                   Progresión            0
## 25            4         0                   Progresión            0
## 26            4         0                   Progresión            1
## 27            4         2 Fin del tratamiento previsto            0
## 28            4         0                   Progresión            1
## 29            4         3                    Toxicidad            0
## 30            4         1                   Progresión            0
## 31            4         0                   Progresión            0
## 32            3         0 Fin del tratamiento previsto            0
## 33            4         0                   Progresión            0
## 34            4        G2 Fin del tratamiento previsto            1
##    NLR1C_corte5 Histología_num Estadio_num Toxicidad Interrupc_tto Enf_neurod
## 1             0              0           4         1             1          0
## 2             1              2           4         1             1          0
## 3             0              0           4         1             1          0
## 4             0              1           3         0             1          0
## 5             0              1           4         0             1          0
## 6             0              2           4         1             1          0
## 7             0              1           4         1             1          0
## 8             0              1           3         1             1          1
## 9             0              1           3         0             1          1
## 10            1              0           4         1             1          0
## 11            1              0           4         0             1          0
## 12            0              0           4         0             1          0
## 13            0              0           4         1             1          0
## 14            0              2           4         0             1          0
## 15            1              0           4         1             1          0
## 16            0              0           4         1             1          0
## 17            0              0           4         0             1          0
## 18            0              0           4         1             1          0
## 19            0              2           4         1             1          0
## 20            1              0           4         1             1          0
## 21            1              0           4         0             1          1
## 22            0              1           4         1             1          0
## 23            0              0           4         0             1          0
## 24            0              0           4         0             1          0
## 25            0              0           4         0             1          0
## 26            1              0           4         0             1          0
## 27            0              2           4         1             1          0
## 28            1              0           4         0             1          0
## 29            0              0           4         1             1          0
## 30            0              0           4         1             1          0
## 31            0              0           4         0             1          0
## 32            0              2           3         0             1          0
## 33            0              0           4         0             0          0
## 34            0              0           4         1             1          0
##    Sexo ECOG Progresion Cardiop Diabetes
## 1     2    1          0       0        0
## 2     1    2          0       0        0
## 3     2    0          1       0        0
## 4     2    0          1       1        0
## 5     2    1          1       0        0
## 6     2    1          0       0        0
## 7     1    1          1       0        1
## 8     2    2          0       1        0
## 9     2    1          1       1        0
## 10    2    1          0       0        0
## 11    2    2          1       0        0
## 12    2    1          0       1        0
## 13    1    1          1       0        1
## 14    2    1          1       0        0
## 15    1    2          1       0        0
## 16    2    1          1       0        0
## 17    1    0          0       0        0
## 18    2    1          0       0        0
## 19    1    1          1       0        0
## 20    2    0          0       0        0
## 21    2    2          1       0        1
## 22    2    1          1       0        0
## 23    2    1          0       0        0
## 24    1    1          1       0        0
## 25    2    1          1       0        0
## 26    1    1          1       0        0
## 27    1    1          0       0        0
## 28    2    1          1       0        0
## 29    2    1          1       0        0
## 30    2    1          1       0        0
## 31    2    1          1       0        0
## 32    2    0          0       0        1
## 33    1    2          1       0        0
## 34    2    1          0       0        0
redondear = c("Idpac","Histologia","Afectacion_ganglionar","Afectacion_metastasica","Estadio","Estatinas","primera_eval_num","Mejor_resp_num",
              "Tipo_tox","Tamaño_tumor","Grado_tox","Motivo_inter","NLR1C_corte4","NLR1C_corte5","Histología_num","Estadio_num","Toxicidad","Interrupc_tto",
              "Enf_neurod","Sexo","ECOG","Progresion","Cardiop","Diabetes")

sapply(df_imputado2[redondear], class)
##                  Idpac             Histologia  Afectacion_ganglionar 
##               "factor"               "factor"               "factor" 
## Afectacion_metastasica                Estadio              Estatinas 
##               "factor"               "factor"               "factor" 
##       primera_eval_num         Mejor_resp_num               Tipo_tox 
##               "factor"               "factor"               "factor" 
##           Tamaño_tumor              Grado_tox           Motivo_inter 
##               "factor"               "factor"               "factor" 
##           NLR1C_corte4           NLR1C_corte5         Histología_num 
##               "factor"               "factor"               "factor" 
##            Estadio_num              Toxicidad          Interrupc_tto 
##               "factor"               "factor"               "factor" 
##             Enf_neurod                   Sexo                   ECOG 
##               "factor"               "factor"               "factor" 
##             Progresion                Cardiop               Diabetes 
##               "factor"               "factor"               "factor"
df_imputado2[redondear] <- lapply(df_imputado2[redondear], as.numeric)

df_imputado2[redondear] <- round(df_imputado2[redondear], 0)
df_imputado2 <- lapply(df_imputado2, as.factor)
df_completo <- cbind(df_imputado1, df_imputado2)

3.3 Create variables response as factor/numerical:

asignar_valor_primera_eval <- function(valor) {
  if (valor == "RP") {
    return(1)
  } else if (valor %in% c("PS", "EE")) {
    return(2)
  } else if (valor == "PE") {
    return(3)
  } else {
    return(NA)  
  }
}

df_completo <- df_completo %>% 
  mutate(pri_eval_num_ok = sapply(primera_eval, asignar_valor_primera_eval))
asignar_valor_mejor_resp <- function(valor) {
  if (valor == "RC") {
    return(0)
  } else if (valor == "RP") {
    return(1)
  } else if (valor == "EE") {
    return(2)
  } else if (valor == "PE") {
    return(3)
  } else {
    return(NA)  # Manejo de otros valores, si es necesario
  }
}

df_completo <- df_completo %>% 
  mutate(mejor_resp_num_ok = sapply(Mejor_resp, asignar_valor_mejor_resp))

4 ANÁLISIS DESCRIPTIVO:

columnas_numericas <- sapply(df_completo, is.numeric)

for (columna in names(df_completo[columnas_numericas])) {
  cat("Variable:", columna, "\n")
  cat("Summary:\n")
  print(summary(df_completo[[columna]]))
  
  cat("Histogram:\n")
  hist(df_completo[[columna]], main = paste("Histogram of", columna), xlab = columna)
  
  cat("Boxplot:\n")
  boxplot(df_completo[[columna]], main = paste("Boxplot of", columna))

  cat("Density graph:\n")
  plot(density(df_completo[[columna]]), main = paste("Density of", columna))
  
  cat("\n")
}
## Variable: Edad_dx 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   46.00   60.00   65.50   65.35   71.00   82.00 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Anciano 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  0.0000  0.3529  1.0000  1.0000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Peso 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   47.00   62.25   67.00   70.16   77.28  102.00 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Talla 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.500   1.593   1.630   1.656   1.728   1.910 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: IMC 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   18.36   22.53   25.11   25.57   28.21   35.63 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Porcentaje_perdpeso 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.00000 0.00000 0.03450 0.04584 0.07300 0.22900 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Exp_tab 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    0.00   37.00   50.00   51.68   60.00  200.00 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: PD_L1 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    2.00   70.00   80.00   78.88   93.75  100.00 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Col_total 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   111.0   153.2   189.0   187.4   205.0   397.0 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: LDH 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   156.0   184.0   200.0   263.7   264.0  1644.0 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Prot_tot 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   5.400   6.900   7.000   7.006   7.300   8.900 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Albumina 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.800   3.700   4.000   3.912   4.200   4.400 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Hb 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   10.60   11.95   13.00   13.16   14.07   16.70 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Leucoc_tot 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    4000    7625    9850   10012   12300   20500 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Neutrofilos 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    2500    5075    7200    7162    8700   13400 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Linf_tot 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     400    1125    1500    1650    2150    3500 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Plaquetas 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  112000  229500  283000  298941  337250  709000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: NLR_pre 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.670   2.925   3.830   5.940   6.060  24.600 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: PLR_pre 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    71.5   131.7   177.2   232.9   251.0   928.0 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: PNI_pre 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   32.00   45.50   48.75   47.42   50.88   59.50 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: ALI_pre 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    3.20   14.64   26.42   26.86   32.73   67.80 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: SII_pre 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  250250  907950 1076325 1689960 1905679 8723200 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Prot_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   4.600   6.800   7.050   7.044   7.375   9.100 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Alb_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.100   3.700   3.950   3.906   4.100   4.600 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Hb_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    8.40   11.60   12.30   12.89   14.50   16.10 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Leucoc_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    3600    7325    9100    9435   12375   16100 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Neutr_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1700    4450    6250    6318    8300   12100 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Linf_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     600    1100    1750    1894    2725    3600 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Plaq_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  112000  246250  330500  336206  428500  650000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: NLR_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.280   2.095   3.255   4.040   5.048  10.400 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: PLR_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   83.45  127.03  160.43  211.81  250.80  571.25 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: PNI_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   10.00   43.00   49.25   47.33   53.88   60.50 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: SII_1C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  276556  763778 1050214 1341856 1505244 4815200 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Prot_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   5.300   6.950   7.212   7.223   7.500   8.800 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Alb_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.900   3.900   4.013   4.013   4.200   4.600 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Hb_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    8.60   11.45   13.15   13.15   14.70   16.70 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Leucoc_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    3800    7300    8750    9106   10125   19400 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Neutr_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1800    4325    5600    5797    6175   16100 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Linf_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     600    1400    2091    2091    2725    4000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Plaq_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     285  243250  268500  305884  335000  858000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: NLR_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.143   1.828   2.591   3.349   3.752  10.083 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: NLR2C_corte4o5 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    0.00    0.00    0.00    0.25    0.25    1.00 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: PLR_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    0.16  109.75  137.75  177.59  185.77  715.00 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: PNI_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   34.00   48.12   51.50   50.71   55.25   59.00 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: SII_2C 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     839  495822  638875 1134690 1210764 8651500 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Prot_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   5.500   6.900   7.094   7.087   7.450   8.500 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Alb_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.100   3.900   4.000   4.018   4.200   4.600 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Hb_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    8.80   11.70   12.95   13.33   15.05   16.90 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Leucoc_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    3100    7425    8700    8682    9625   18400 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Neutr_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1400    4325    5450    5726    6450   13600 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Linf_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     500    1100    1800    1897    2600    4000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Plaq_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   96000  221750  262500  286059  316500  647000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: NLR_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.077   1.801   2.647   4.027   4.438  18.200 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: PLR_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   56.86  104.16  146.46  203.41  222.31 1054.00 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: PNI_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   33.50   44.38   50.00   49.66   55.25   61.00 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: SII_1eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  238800  486505  633308 1265920 1341869 9591400 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: N_ciclos 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1.00    5.00    9.50   15.26   25.75   35.00 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: segunda_eval 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  0.5185  0.5185  1.0000  1.0000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: Exitus 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  1.0000  0.7059  1.0000  1.0000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: SLP 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.7557  5.6263 13.6674 19.2545 34.1766 60.3860 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: SLP_cens 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  0.0000  0.3824  1.0000  1.0000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: SG 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.807  16.033  27.663  26.859  40.025  60.386 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: SG_cens 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  0.0000  0.3235  1.0000  1.0000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: pri_eval_num_ok 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   1.000   2.000   1.765   2.000   3.000 
## Histogram:

## Boxplot:

## Density graph:

## 
## Variable: mejor_resp_num_ok 
## Summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   1.000   1.000   1.353   2.000   3.000 
## Histogram:

## Boxplot:

## Density graph:

columnas_categoricas <- sapply(df_completo, is.factor)

for (columna in names(df_completo[columnas_categoricas])) {
  cat("Variable:", columna, "\n")
  cat("Frequency:\n")
  print(table(df_completo[[columna]]))
  
  cat("Bar graphic:\n")
  barplot(table(df_completo[[columna]]), main = paste("Bar graphic of", columna))
  
  cat("Pie chart:\n")
  pie(table(df_completo[[columna]]), main = paste("Pie chart of", columna))
  
  cat("\n")
}
## Variable: Idpac 
## Frequency:
## 
##  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
##  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1 
## 27 28 29 30 31 32 33 34 
##  1  1  1  1  1  1  1  1 
## Bar graphic:

## Pie chart:

## 
## Variable: Histologia 
## Frequency:
## 
##  1  2  3  4 
## 22  1  6  5 
## Bar graphic:

## Pie chart:

## 
## Variable: Afectacion_ganglionar 
## Frequency:
## 
##  1  2  3  4  5 
##  4  2 16 11  1 
## Bar graphic:

## Pie chart:

## 
## Variable: Afectacion_metastasica 
## Frequency:
## 
##  1  2  3  4 
##  4  4  6 20 
## Bar graphic:

## Pie chart:

## 
## Variable: Estadio 
## Frequency:
## 
##  1  2  3  4  5 
##  1  2  1  6 24 
## Bar graphic:

## Pie chart:

## 
## Variable: Estatinas 
## Frequency:
## 
##  1  2  3 
## 24  1  9 
## Bar graphic:

## Pie chart:

## 
## Variable: primera_eval_num 
## Frequency:
## 
##  1  2  3 
## 15 13  6 
## Bar graphic:

## Pie chart:

## 
## Variable: Mejor_resp_num 
## Frequency:
## 
##  1  2  3  4 
##  5 17  7  5 
## Bar graphic:

## Pie chart:

## 
## Variable: Tipo_tox 
## Frequency:
## 
##  1  2  3  4  5  6  7  8  9 10 
## 15  2  4  1  2  1  4  1  2  2 
## Bar graphic:

## Pie chart:

## 
## Variable: Tamaño_tumor 
## Frequency:
## 
##  1  2  3  4  5  6  7 
##  1  1  4  6 17  4  1 
## Bar graphic:

## Pie chart:

## 
## Variable: Grado_tox 
## Frequency:
## 
##  1  2  3  4  5 
## 15  7  3  8  1 
## Bar graphic:

## Pie chart:

## 
## Variable: Motivo_inter 
## Frequency:
## 
##  1  2  3  4  5  6 
##  1  1  2  6 15  9 
## Bar graphic:

## Pie chart:

## 
## Variable: NLR1C_corte4 
## Frequency:
## 
##  1  2 
## 22 12 
## Bar graphic:

## Pie chart:

## 
## Variable: NLR1C_corte5 
## Frequency:
## 
##  1  2 
## 26  8 
## Bar graphic:

## Pie chart:

## 
## Variable: Histología_num 
## Frequency:
## 
##  1  2  3 
## 22  6  6 
## Bar graphic:

## Pie chart:

## 
## Variable: Estadio_num 
## Frequency:
## 
##  1  2 
##  4 30 
## Bar graphic:

## Pie chart:

## 
## Variable: Toxicidad 
## Frequency:
## 
##  1  2 
## 16 18 
## Bar graphic:

## Pie chart:

## 
## Variable: Interrupc_tto 
## Frequency:
## 
##  1  2 
##  1 33 
## Bar graphic:

## Pie chart:

## 
## Variable: Enf_neurod 
## Frequency:
## 
##  1  2 
## 31  3 
## Bar graphic:

## Pie chart:

## 
## Variable: Sexo 
## Frequency:
## 
##  1  2 
## 10 24 
## Bar graphic:

## Pie chart:

## 
## Variable: ECOG 
## Frequency:
## 
##  1  2  3 
##  5 23  6 
## Bar graphic:

## Pie chart:

## 
## Variable: Progresion 
## Frequency:
## 
##  1  2 
## 13 21 
## Bar graphic:

## Pie chart:

## 
## Variable: Cardiop 
## Frequency:
## 
##  1  2 
## 30  4 
## Bar graphic:

## Pie chart:

## 
## Variable: Diabetes 
## Frequency:
## 
##  1  2 
## 30  4 
## Bar graphic:

## Pie chart:

# ruta_archivo <- "C:/Users/magob/Desktop/PROYECTO/df_definitivo.xlsx"
# 
# write.xlsx(df_completo, file = ruta_archivo, rowNames = TRUE)
# 
# if (file.exists(ruta_archivo)) {
#   cat("¡Los datos se han guardado exitosamente en", ruta_archivo, "!\n")
# } else {
#   cat("Hubo un problema al guardar los datos. Por favor, verifica la ruta y el nombre del archivo.\n")
# }